package cn.stack.springframework.test;

import cn.bugstack.springframework.aop.AdvisedSupport;
import cn.bugstack.springframework.aop.TargetSource;
import cn.bugstack.springframework.aop.aspectj.AspectJExpressionPointcut;
import cn.bugstack.springframework.aop.framework.Cglib2AopProxy;
import cn.bugstack.springframework.aop.framework.JdkDynamicAopProxy;
import cn.stack.springframework.test.bean.IUserService11;
import cn.stack.springframework.test.bean.UserService11;
import cn.stack.springframework.test.bean.UserServiceInterceptor11;
import org.junit.Test;

public class ApiTest11 {
    @Test
    public void tset_dynamic(){
        //目标对象
        IUserService11 userService11 = new UserService11();
        //组装代理信息
        AdvisedSupport advisedSupport = new AdvisedSupport();
        advisedSupport.setTargetSource(new TargetSource(userService11));
        advisedSupport.setMethodInterceptor(new UserServiceInterceptor11());
        advisedSupport.setMethodMatcher(new AspectJExpressionPointcut("execution(* cn.stack.springframework.test.bean.IUserService11.*(..))"));

        IUserService11 proxy_jdk= (IUserService11) new JdkDynamicAopProxy(advisedSupport).getProxy();
        System.out.println("测试结果: "+proxy_jdk.queryUserInfo());

        IUserService11 proxy_cglib=(IUserService11) new Cglib2AopProxy(advisedSupport).getProxy();
        System.out.println("测试结果: "+proxy_cglib.register("鲜花"));
    }
}
